package com.officegameapp.service;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.officegameapp.db.dao.DAOFactory;
import com.officegameapp.db.dao.IGameDAO;
import com.officegameapp.db.dao.ITeamDAO;
import com.officegameapp.db.entities.Game;
import com.officegameapp.db.entities.Team;

@Path("/games")
public class GameService {

	private IGameDAO gameDAO;
	private ITeamDAO teamDAO;
	
	public GameService() {
		gameDAO = DAOFactory.getDAOFactory(DAOFactory.MYSQL_DAO).getGameDAO();
		teamDAO = DAOFactory.getDAOFactory(DAOFactory.MYSQL_DAO).getTeamDAO();
	}
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public List<Game> getGames() {
		List<Game> games = gameDAO.getGames();
		return games;
	}

	@POST
	@Produces(MediaType.APPLICATION_JSON)
//	@Consumes(MediaType.APPLICATION_JSON)
	public Game createGame() {
		
		Game game = new Game();
		Team firstTeam = teamDAO.read(2l);
		Team secondTeam = teamDAO.read(3l);
		game.setFirstTeam(firstTeam);
		game.setSecondTeam(secondTeam);
		gameDAO.persist(game);
		
		return game;
	}
	
}
